#!/bin/sh

set -e

export BUILD_ROOT="${BUILD_ROOT:=$HOME/vbam-build-linux}"

. "$(dirname "$0")/../builder/unix.sh"

table_line_append DIST_EXTRA_LIBS shared-mime-info '-Wl,--start-group -lmount -lblkid -luuid -Wl,--end-group'

table_line_append DIST_EXTRA_LDFLAGS ffmpeg -lunwind

table_insert_before DISTS autoconf '
    libunwind       http://download.savannah.nongnu.org/releases/libunwind/libunwind-1.2.tar.gz                 lib/libunwind.a
'

table_insert_before DISTS glib '
    libcap          https://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/libcap-2.25.tar.xz       lib/libcap.a
    libudev         https://github.com/systemd/systemd/archive/v237.tar.gz                                      lib/libudev.a
    util-linux      https://www.kernel.org/pub/linux/utils/util-linux/v2.31/util-linux-2.31.tar.xz              lib/libmount.a
'

table_line_append DIST_PATCHES libcap 'https://604802.bugs.gentoo.org/attachment.cgi?id=460354'

table_line_append DIST_EXTRA_LDFLAGS util-linux '-lintl -liconv'

table_line_append DIST_PATCHES libudev " \
https://gist.githubusercontent.com/rkitover/b639097f5c0304c5c4c66d19159fb9a2/raw/7c7bb75747c99fda2ed309c3337338279eff1527/systemd-237-static-libudev.patch \
"

table_line_append DIST_EXTRA_LDFLAGS libudev '-Wl,--allow-multiple-definition -Wl,--start-group -lglib-2.0 -lgio-2.0 -lgmodule-2.0 -lgobject-2.0 -lpcre -lz -lffi -lpthread -lresolv -ldl -lintl -liconv -luuid -Wl,--end-group'

table_line_append DIST_ARGS libudev '-Dlink-udev-shared=false'

table_line_append DIST_MAKE_ARGS libudev 'src/udev/libudev.a'

table_line_append DIST_INSTALL_OVERRIDES libudev " \
    mkdir -p \"\$BUILD_ROOT/root/lib/pkgconfig\"; \
    mkdir -p \"\$BUILD_ROOT/root/include\"; \
    cp -a src/udev/libudev.a \"\$BUILD_ROOT/root/lib\"; \
    cp -a src/libudev/libudev.pc \"\$BUILD_ROOT/root/pkgconfig\"; \
    cp -a ../src/libudev/libudev.h \"\$BUILD_ROOT/root/include\"; \
"

builder "$@"
